﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace DemoWebService
{
    [WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1, Namespace="urn:Amf4Asmx")]
    [WebService(Namespace = "urn:Amf4Asmx")]
    public class HelloWorldService : WebService
    {
        public struct NameList
        {
            public string[] names;
        }

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string HelloWorldNamed(string name)
        {
            return string.Format("Hello, {0}!", name);
        }

        [WebMethod]
        public string HelloWorldNames(string[] names)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < names.Length; i++)
            {
                sb.AppendLine(string.Format("Hello, {0}!", names[i]));
            }
            return sb.ToString();
        }

        [WebMethod]
        public string HelloWorldNames2(NameList list)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < list.names.Length; i++)
            {
                sb.AppendLine(string.Format("Hello, {0}!", list.names[i]));
            }
            return sb.ToString();
        }

        [WebMethod]
        public NameList HelloWorldStruct(NameList list)
        {
            List<string> result = new List<string>();
            for (int i = 0; i < list.names.Length; i++)
            {
                result.Add(string.Format("Hello, {0}!", list.names[i]));
            }
            return new NameList() { names = result.ToArray() };
        }

        [WebMethod]
        public int GetTime()
        {
            return 10;
        }

        public enum Status
        {
            Success,
            Error
        }

        [WebMethod]
        public Status GetStatus(Status status)
        {
            return status;
        }


        [WebMethod]
        public int MultipleOut(out string name)
        {
            name = "test";
            return 10;
        }

        [WebMethod]
        public void Void()
        {
        }

        public TestHeader SomeHeader { get; set; }
        public TestHeader SomeOtherHeader { get; set; }

        [WebMethod, SoapHeader("SomeHeader", Direction = SoapHeaderDirection.In), SoapHeader("SomeOtherHeader", Direction = SoapHeaderDirection.Out)]
        public void HeaderTest()
        {
            SomeOtherHeader = new TestHeader() { Text = SomeHeader.Text };
        }

        [WebMethod, SoapHeader("SomeHeader", Direction = SoapHeaderDirection.In)]
        public string HeaderInTest()
        {
            return SomeHeader.Text;
        }
    }
}
